package com.qkjia.day01;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class Test11_NotSafe {
    public static void main(String[] args) {
        //线程不安全
        //Map<String, String> map = new HashMap<>();
        //线程安全 效率低 加锁
        //Map<String, String> map = new Hashtable<>();
        //线程安全 效率高
        Map<String, String> map = new ConcurrentHashMap<>();
        for (int i = 0; i <100 ; i++) {
            String key=i+"";
            new Thread(()->{
                map.put(key,UUID.randomUUID().toString().substring(0,5));
                System.out.println(map);
            },""+i).start();
        }
    }
}
